import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class TestCase:
    def __init__(self):
        self.driver = webdriver.Chrome()  # 打开浏览器
        self.driver.maximize_window()  # 最大化窗口
        self.driver.get('https://ecshop.test2.shopex123.com/')  # 输入ecshop网址

    # 定位首页搜索框
    def search(self, text):
        keyword = self.driver.find_element(By.ID, 'keyword')
        keyword.send_keys(text)

    # 定位首页搜索按钮
    def btn_search(self):
        btn_search = self.driver.find_element(By.NAME, 'imageField')
        btn_search.click()

    # 定位首页登录按钮
    def btn_login(self):
        btn_login = self.driver.find_element(By.LINK_TEXT, '[ 请登录 ]')
        btn_login.click()

    # 定位登录成功操作
    def login(self):
        # 定位登录输入name:username
        ipt_username = self.driver.find_element(By.NAME, 'username')
        ipt_username.send_keys('yinkaili')
        # 定位密码输入name:password
        ipt_pw = self.driver.find_element(By.NAME, 'password')
        ipt_pw.send_keys('666666')

        #  定位:请保存我这次的登录信息。
        save_infor = self.driver.find_element(By.TAG_NAME, 'label')
        save_infor.click()

        # 定位登录按钮name:submit
        btn_login1 = self.driver.find_element(By.NAME, 'submit')
        btn_login1.click()

    # 定位登录界面的没有账号:立即注册
    def btn_rregister(self):
        btn_rregister = self.driver.find_element(By.LINK_TEXT, '立即注册')
        btn_rregister.click()

    # 定位登录界面的忘记密码
    def login_forget_pw(self):
        login_forget_pw = self.driver.find_element(By.LINK_TEXT, '忘记密码?')
        login_forget_pw.click()

    # 定位首页注册按钮
    def btn_register(self):
        btn_register = self.driver.find_element(By.LINK_TEXT, '[ 免费注册 ]')
        btn_register.click()

    # 定位注册成功操作
    def register(self):
        # 定位用户名username,并输入
        user_name = self.driver.find_element(By.ID, 'username')
        user_name.send_keys('weilong7')
        # 定位邮箱email,并输入
        email = self.driver.find_element(By.ID, 'email')
        email.send_keys('8888888888888@qq.com')
        # 定位密码password1,并输入
        password_one = self.driver.find_element(By.ID, 'password1')
        password_one.send_keys('666666')
        # 定位确认密码confirm_password,并输入
        confirm_password = self.driver.find_element(By.ID, 'confirm_password')
        confirm_password.send_keys('666666')
        # 定位取消看过协议name:agreement
        # agreement = self.driver.find_element(By.NAME, 'agreement')
        # # 点击协议
        # agreement.click()
        # 定位同意注册按钮name:Submit
        btn_agree = self.driver.find_element(By.CLASS_NAME, 'signup_button')
        # 点击注册按钮
        btn_agree.click()

        # 定位已有账号,我要登录并点击LINK_TEXT:立即登录

    # 定位注册界面的已有账号,立即登录
    def btn_have_login(self):
        btn_have_login = self.driver.find_element(By.LINK_TEXT, '立即登录')
        btn_have_login.click()

        # 定位您忘记密码了并点击

    # 定位注册界面的忘记密码
    def btn_forget_pw(self):
        btn_forget_pw = self.driver.find_element(By.LINK_TEXT, '您忘记密码了吗？')
        btn_forget_pw.click()

    # 退出浏览器
    def quit(self):
        time.sleep(3)
        self.driver.quit()


if __name__ == '__main__':
    case = TestCase()
    # case.btn_search()
    # case.btn_login()
    case.btn_register()
    case.register()
    # case.login()
    # case.btn_rregister()
    # case.register()
    # case.search('欧莱雅')
    # case.btn_search()
    # case.quit()
